<template>
  <div>
    <el-form :inline="true" :model="search" class="demo-form-inline">
      <el-row class="table-head-box">
        <el-col :span="24" class="flex flex-end input-box">
          <!-- <el-input v-model="search.eqParam.month" clearable placeholder="月份"></el-input> -->
          <el-date-picker
            clearable
            v-model="search.eqParam.month"
            type="month"
            value-format="yyyy-MM"
            placeholder="选择月"
          >
          </el-date-picker>
          <el-button type="primary" icon="el-icon-search" @click="searchHandler"
            >查询</el-button
          >
        </el-col>
      </el-row>
    </el-form>
    <el-table
      :data="userList"
      border
      style="width: 100%"
      tooltip-effect="dark"
      size="mini"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="storeName" label="门店名称" width="150">
      </el-table-column>
      <el-table-column prop="month" label="月份" width="150"> </el-table-column>
      <el-table-column prop="orderNumb" label="订单数量" width="150">
      </el-table-column>
      <el-table-column prop="money" label="结款金额" width="150">
      </el-table-column>
      <el-table-column prop="status" label="结账状态" width="150">
        <template slot-scope="scope">
          <div v-if="scope.row.status == 0">未结款</div>
          <div v-if="scope.row.status == 1">已结款</div>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="260">
        <template slot-scope="scope">
          <el-button
            class="el-icon-edit"
            type="primary"
            size="mini"
            @click="updateHandler(scope.$index, scope.row)"
            >结账</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-row>
      <el-col :span="24" style="text-align: right">
        <el-pagination
          background
          layout="total,prev, pager, next"
          :page-count="search.size"
          :current-page="search.current"
          :total="search.total"
          @current-change="sizeChangeHandler"
        >
        </el-pagination>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { orderRevenueListUrl, orderRevenueSaveUrl } from "@/utils/common";
export default {
  components: {},
  data() {
    return {
      userList: [],
      merchart: null,
      showMerchantDialog: false,
      authorizationDialog: false,
      userId: null,
      search: {
        current: 1,
        size: 10,
        total: 0,
        lkParam: { userName: "" },
        eqParam: { status: 0, month: "" },
      },
    };
  },
  mounted() {
    this.loadOrders();
  },
  methods: {
    addStoreHandler: function () {
      this.merchart = { type: 1, status: 1 };
      this.showMerchantDialog = true;
    },
    updateHandler: function (index, row) {
      //更新账单状态
      row.status = 1;
      this.axios.post(orderRevenueSaveUrl, row).then((res) => {
        if (res.data.status == "SUCCESS") {
          this.$message({
            showClose: true,
            message: "结账成功",
          });
          this.loadOrders();
        }
      });
    },
    closeHandler: function () {
      this.showMerchantDialog = false;
      this.loadOrders();
    },
    loadOrders() {
      this.axios
        .post(orderRevenueListUrl, this.search)
        .then((response) => {
          var data = response.data.data;
          this.userList = data.records;
          this.search.total = data.total;
        })
        .catch((response) => {
          console.log("response -   " + response);
        });
    },
    sizeChangeHandler: function (value) {
      this.search.current = value;
      this.loadOrders();
    },
    searchHandler: function () {
      this.search.current = 1;
      this.loadOrders();
    },
  },
};
</script>
<style scoped>
.grid-content {
  text-align: left;
  height: 45px;
}
</style>
